<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>修改顾客信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="update">
        <input type="hidden" name="id" id="id"/>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                联系方式
            </label>
            <div class="layui-input-inline">
                <input type="tel" class="layui-input"
                       lay-verify="phone|number" name="phone" id="phone" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                顾客姓名
            </label>
            <div class="layui-input-inline">
                <input class="layui-input" name="name" id="name"
                       lay-verify="required" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="customerCard" class="layui-form-label">
                身份证号码
            </label>
            <div class="layui-input-inline">
                <input type="number" id="customerCard" name="customerCard" required=""
                       lay-verify="required|number"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="sex" class="layui-form-label">
                性别
            </label>
            <div class="layui-input-inline">
                <select name="sex" id="sex" class="layui-select-group">
                    <option name="sex1" value="1">男</option>
                    <option name="sex1" value="0">女</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="age" class="layui-form-label">
                年龄
            </label>
            <div class="layui-input-inline">
                <input type="number" id="age" name="age" required="" lay-verify="required|number"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="checkId" class="layui-form-label">
                入住订单号
            </label>
            <div class="layui-input-inline">
                <select name="checkId" id="checkId" class="layui-select-group">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="remark" class="layui-form-label">
                备注
            </label>
            <div class="layui-input-inline">
                <input type="text" id="remark" name="remark" required="" lay-verify="remark"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button type="button" class="layui-btn" lay-filter="modify" lay-submit="">
                修改信息
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer','laydate'], function () {
        var $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        var laydate = layui.laydate;
        //执行一个laydate实例
        //自定义验证规则
        form.verify({
            //验证固定号码是否有误
            // roomTel: [/\d{3,4}[-]\d{7}/, "房间固定号码格式有误"]
        });
        $.get({
            url: '/checkin/list',
            dataType: 'json',
            success: function (res) {
                var checkList = res.data;
                var selectList = $("#checkId");
               checkList.forEach(function (ele, index) {
                    var option = $('<option></option>');
                    //如果该类型在下拉框中没有，则添加
                    if ($('#checkId option[value=' + ele['liveId'] + ']').length == 0) {
                        option.val(ele['liveId']);
                        option.text(ele['liveId']);
                        option.appendTo(selectList);
                    }
                    form.render('select');
                });
                //获取父页面的性别和入住单号等值，渲染到表单上
                var sex = parent.$('#sex').val();
                var checkId = parent.$('#checkId').val();
                switch (sex) {
                    case '男':sex = '1';break;
                    case '女':sex = '0';break;
                }
                console.log('checkId,',checkId);
                $('#sex option[value='+sex+']').prop('selected',true);
                $('#checkId option[value='+checkId+']').prop('selected',true);
                console.log('checkId',$('#checkId option[value='+checkId+']'));
                form.render('select');
            }
        });
        //监听提交
        form.on('submit(modify)', function (data) {
            //发异步，把数据提交给后台
            console.log($('#update').serialize());
            $.ajax({
                url:'/customer/edit',
                type:'POST',
                data: $('#update').serialize(),
                success:function (res) {
                    console.log($('#update').serialize());
                    if(res.status==0){
                        layer.closeAll('loading');
                        layer.load(2);
                        layer.alert("修改成功", {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.location.reload();
                        });
                    } else{
                        layer.alert(res.msg, {icon: 5})
                    }
                },
            })
            return false;



        });


    });
</script>

</body>

</html>